package haw.pr2.A3.implementations;

import haw.pr2.A3.interfaces.Location;
import haw.pr2.A3.interfaces.StowageLocation;

/**
 *
 * @author Fabian Heidorn, Alexander Kaack
 */
public class StowageLocationImpl implements StowageLocation {
    
    final int bay;
    final int row;
    final int tier;
    
    public StowageLocationImpl(int bay, int row, int tier) {
        this.bay=bay;
        this.row=row;
        this.tier=tier;
    }

    @Override
    public int bay() {
        return this.bay;
    }

    @Override
    public int row() {
        return this.row;
    }

    @Override
    public int tier() {
        return this.tier;
    }

    @Override
    public boolean isNull() {
        return false;
    }


    @Override
    public int compareTo(Location o) {
        if(this.bay()-((StowageLocation)o).bay() == 0) {
            if(this.row()-((StowageLocation)o).row() == 0) {
                if(this.tier()-((StowageLocation)o).tier() == 0) {
                    return 0;
                }
                return this.tier()-((StowageLocation)o).tier();
            }
            return this.row()-((StowageLocation)o).row();
        }
        return this.bay()-((StowageLocation)o).bay();
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (!(obj instanceof StowageLocation)) return false;
        return this.compareTo((StowageLocation)obj) == 0;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 71 * hash + this.bay;
        hash = 71 * hash + this.row;
        hash = 71 * hash + this.tier;
        return hash;
    }


}
